package group.hhsw.purchase.service.impl;

import group.hhsw.common.model.params.Check;
import group.hhsw.common.model.vo.DetailOrder;
import group.hhsw.feign.clients.ProductClient;
import group.hhsw.feign.clients.UserProductClient;
import group.hhsw.purchase.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("9")
public class CheckSingleDayLimit implements PurchaseService {

    @Autowired
    private ProductClient productClient;

    @Autowired
    private UserProductClient userProductClient;

    @Override
    public DetailOrder atomicService(Check check) {
        //这里只进行简单逻辑演示，未涉及实际数据
        Long dayLimit = productClient.getSingleDayLimit(check.getProductId());
        //查询用户一天购买了多少钱的产品
        Long amount = userProductClient.getUserPurchaseAmount(check.getAccount(), check.getProductId());
        DetailOrder detailOrder = new DetailOrder();
        detailOrder.setSingleDayLimitAmountIsOk(amount < dayLimit);
        return detailOrder;
    }
}
